package practicacupfinal;

import java_cup.runtime.*;

%%

%{
	   int yyline() { return yyline; }
	   int yycolumn() { return yycolumn; }
%}

%{
  public void imprime(String str){
    System.out.println(str + " FILA: " + yyline + " COL: " + yycolumn);
  }
%}

%class Scanner

%unicode
%cup 
%line 
%column

/*********************** Comentarios ********************************/
_comment = "@" [^\r\n]* (\r|\n|\r\n)

/************************* auxiliares *******************************/
letraMin    = [a-z]
letraMay    = [A-Z]
letra       = {letraMin} | {letraMay}
digito      = [0-9]
digitoNZ    = [1-9]
alfanum     = {letra} | {digito}
decimal     = "." ( 0 | [0-9]* ([1-9] | [1-9] 0))   // \. (0 |  {digito}* {digitoNZ}) 
parteExp    = ("e" | "E") {vnatural} 

/********************* identificador y valores ************************/
vnatural    = 0 | {digitoNZ} {digito}*
//vinteger    = "-"? {vnatural}
vfloat = {vnatural} {decimal}? {parteExp}? // {vnatural} ({decimal} {parteExp}? | {parteExp})
vchar  = \'[^\']*\'
identificador = {letraMin} {alfanum}*

/******************** palabras reservadas *****************************/
program = "program"
consts = "consts"
const = "const"
vars = "vars"
var = "var"
tipos = "tipos"
tipo = "tipo"
subprograms = "subprograms"
subprogram = "subprogram"
instructions = "instructions"
boolean = "boolean"
character = "character"
natural = "natural"
integer = "integer"
float = "float"
if      = "if"
then    = "then"
else    = "else"
endif   = "endif"
while 	= "while"
do	= "do"
endwhile = "endwhile"
in      = "in"
out     = "out"
call    = "call"
swap1   = "swap1()"
swap2   = "swap2()"
int   = "int"
nat   = "nat"
char  = "char"
true = "true"
false = "false"

/************ operadores ********************/
menor = "<"
mayor = ">"
menigual = "<="
mayigual = ">="
igual = "=="
noigual = "!="
suma = "+"
resta = "-"
mul = "*"
div = "/"
mod = "%"
and = "and"
or = "or"
not = "not"
despder = ">>"
despizq = "<<"

/****************** otros ********************/
dp = ":"
pc = ";"
coma = ","
asig = "="
llabierta = "{"
llcerrada = "}"
pabierto = "("
pcerrado = ")"
cabierto = "["
ccerrado = "]"
gbajo = "_"

%%


[\t\r\n ] {}
#[^\n]*   {}

/********************* valores ************************/
{vnatural}  {imprime("VNATURAL:" + yytext()); return new Symbol(sym.VNATURAL, yyline(), yycolumn(), yytext());}
//{vinteger}  {imprime("VINTEGER:" + yytext()); return new Symbol(sym.VINTEGER, yyline(), yycolumn(), yytext());}
{vfloat}  {imprime("VFLOAT:" + yytext()); return new Symbol(sym.VFLOAT, yyline(), yycolumn(), yytext());}
{vchar} {imprime("VCHAR:" + yytext()); return new Symbol(sym.VCHAR, yyline(), yycolumn(), yytext());}

/******************** palabras reservadas *****************************/
{program} {imprime("program"); return new Symbol(sym.PROGRAM, yyline(), yycolumn(), yytext());}
{consts} {imprime("consts"); return new Symbol(sym.CONSTS, yyline(), yycolumn(), yytext());}
{const} {imprime("const"); return new Symbol(sym.CONST, yyline(), yycolumn(), yytext());}
{vars} {imprime("vars"); return new Symbol(sym.VARS, yyline(), yycolumn(), yytext());}
{var} {imprime("var"); return new Symbol(sym.VAR, yyline(), yycolumn(), yytext());}
{tipos} {imprime("tipos"); return new Symbol(sym.TIPOS, yyline(), yycolumn(), yytext());}
{tipo} {imprime("tipo"); return new Symbol(sym.TIPO, yyline(), yycolumn(), yytext());}
{subprograms} {imprime("subprograms"); return new Symbol(sym.SUBPROGRAMS, yyline(), yycolumn(), yytext());}
{subprogram} {imprime("subprogram"); return new Symbol(sym.SUBPROGRAM, yyline(), yycolumn(), yytext());}
{instructions} {imprime("instructions"); return new Symbol(sym.INSTRUCTIONS, yyline(), yycolumn(), yytext());}
{boolean} {imprime("boolean"); return new Symbol(sym.BOOLEAN, yyline(), yycolumn(), yytext());}
{character} {imprime("character"); return new Symbol(sym.CHARACTER, yyline(), yycolumn(), yytext());}
{natural} {imprime("natural"); return new Symbol(sym.NATURAL, yyline(), yycolumn(), yytext());}
{integer} {imprime("integer"); return new Symbol(sym.INTEGER, yyline(), yycolumn(), yytext());}
{float} {imprime("float"); return new Symbol(sym.FLOAT, yyline(), yycolumn(), yytext());}
{true}  {imprime("TRUE:"); return new Symbol(sym.TRUE, yyline(), yycolumn(), yytext());}
{false}  {imprime("FALSE:"); return new Symbol(sym.FALSE, yyline(), yycolumn(), yytext());}

{if} {imprime("if"); return new Symbol(sym.IF, yyline(), yycolumn(), yytext());}
{then} {imprime("then"); return new Symbol(sym.THEN, yyline(), yycolumn(), yytext());}
{else} {imprime("else"); return new Symbol(sym.ELSE, yyline(), yycolumn(), yytext());}
{endif} {imprime("endif"); return new Symbol(sym.ENDIF, yyline(), yycolumn(), yytext());}
{while} {imprime("while"); return new Symbol(sym.WHILE, yyline(), yycolumn(), yytext());}
{do} {imprime("do"); return new Symbol(sym.DO, yyline(), yycolumn(), yytext());}
{endwhile}  {imprime("endwhile"); return new Symbol(sym.ENDWHILE, yyline(), yycolumn(), yytext());}
{in} {imprime("in"); return new Symbol(sym.IN, yyline(), yycolumn(), yytext());}
{out} {imprime("out"); return new Symbol(sym.OUT, yyline(), yycolumn(), yytext());}
{call} {imprime("call"); return new Symbol(sym.CALL, yyline(), yycolumn(), yytext());}
{swap1} {imprime("swap1"); return new Symbol(sym.SWAP1, yyline(), yycolumn(), yytext());}
{swap2} {imprime("swap2"); return new Symbol(sym.SWAP2, yyline(), yycolumn(), yytext());}
{char} {imprime("char"); return new Symbol(sym.CHAR, yyline(), yycolumn(), yytext());}
{int} {imprime("int"); return new Symbol(sym.INT, yyline(), yycolumn(), yytext());}
{nat} {imprime("nat"); return new Symbol(sym.NAT, yyline(), yycolumn(), yytext());}

/************ operadores ********************/

{menor} {imprime("<"); return new Symbol(sym.MENOR, yyline(), yycolumn(), yytext());}
{mayor} {imprime(">"); return new Symbol(sym.MAYOR, yyline(), yycolumn(), yytext());}
{menigual} {imprime("<="); return new Symbol(sym.MENIGUAL, yyline(), yycolumn(), yytext());}
{mayigual} {imprime(">=t"); return new Symbol(sym.MAYIGUAL, yyline(), yycolumn(), yytext());}
{igual} {imprime("=="); return new Symbol(sym.IGUAL, yyline(), yycolumn(), yytext());}
{noigual} {imprime("!="); return new Symbol(sym.NOIGUAL, yyline(), yycolumn(), yytext());}
{suma} {imprime("+"); return new Symbol(sym.SUMA, yyline(), yycolumn(), yytext());}
{resta} {imprime("-"); return new Symbol(sym.RESTA, yyline(), yycolumn(), yytext());}
{mul} {imprime("*"); return new Symbol(sym.MUL, yyline(), yycolumn(), yytext());}
{div} {imprime("/"); return new Symbol(sym.DIV, yyline(), yycolumn(), yytext());}
{mod} {imprime("%"); return new Symbol(sym.MOD, yyline(), yycolumn(), yytext());}
{and} {imprime("and"); return new Symbol(sym.AND, yyline(), yycolumn(), yytext());}
{or} {imprime("or"); return new Symbol(sym.OR, yyline(), yycolumn(), yytext());}
{not} {imprime("in"); return new Symbol(sym.NOT, yyline(), yycolumn(), yytext());}
{despder} {imprime(">>"); return new Symbol(sym.DESPDER, yyline(), yycolumn(), yytext());}
{despizq} {imprime("<<"); return new Symbol(sym.DESPIZQ, yyline(), yycolumn(), yytext());}

/****************** otros ********************/
{pc} {imprime("pc"); return new Symbol(sym.PC, yyline(), yycolumn(), yytext()); }
{coma} {imprime("coma"); return new Symbol(sym.COMA, yyline(), yycolumn(), yytext()); }
{dp} {imprime("dp"); return new Symbol(sym.DP, yyline(), yycolumn(), yytext());}
{asig} {imprime("asig"); return new Symbol(sym.ASIG, yyline(), yycolumn(), yytext());}
{llabierta} {imprime("llabierta"); return new Symbol(sym.LLABIERTA, yyline(), yycolumn(), yytext());}
{llcerrada} {imprime("llavecierre"); return new Symbol(sym.LLCERRADA, yyline(), yycolumn(), yytext());}
{pabierto} {imprime("pabierto"); return new Symbol(sym.PABIERTO, yyline(), yycolumn(), yytext());}
{pcerrado} {imprime("pcerrado"); return new Symbol(sym.PCERRADO, yyline(), yycolumn(), yytext());}
{cabierto}  {imprime("corchap"); return new Symbol(sym.CABIERTO, yyline(), yycolumn(), yytext());}
{ccerrado} {imprime("corchcierre"); return new Symbol(sym.CCERRADO, yyline(), yycolumn(), yytext()); }
{gbajo}  {imprime("gbajo"); return new Symbol(sym.GBAJO, yyline(), yycolumn(), yytext()); }

{identificador}  {imprime("IDENT:" + yytext()); return new Symbol(sym.IDENTIFICADOR,  yyline(), yycolumn(), yytext());}

[^]     {return new Symbol(sym.ERROR, yyline(), yycolumn(), yytext());}

/**** [^]     {throw new Error("(" + yyline + ", " + yycolumn + ")" + " Caracter no reconocido: "+yy.text());}  **/
